<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        // 迭代器的使用可以极大的简化数据操作，于是ES6也向js中增加了迭代器特性
        function makeIterator(arr){

            let nextIndex=0;
            return {
                next:function(){
                    if(nextIndex<arr.length){//0<5    1<5  ....   4<5   5<5
                        let temp=arr[nextIndex];//arr[0]  arr[1] ... arr[4]
                        nextIndex++;//1  2 3  4  5
                        return {value:temp,done:false};
                    }else{
                        return {value:undefined,done:true};
                    }
                }
            };
        }
        let arr=[10,20,33,44,55];
        // var arrsIt=makeIterator(arr);
        // var temp1=arrsIt.next();
        // console.log(temp1);
        // var temp2=arrsIt.next();
        // console.log(temp2);
        // var temp3=arrsIt.next();
        // console.log(temp3);
        // var temp4=arrsIt.next();
        // console.log(temp4);
        // var temp5=arrsIt.next();
        // console.log(temp5);
        // var temp6=arrsIt.next();
        // console.log(temp6);

        let arrsIt=makeIterator(arr);
        do{
            var {value,done}=arrsIt.next();
            if(done==false){
                console.log(value);
            }
        }while(!done);

        var arrays=["a","b","c","d"];
        console.log(arrays);
        //ES6为数组内置了迭代器
        // let arraysIt=arrays[Symbol.iterator]();
        // console.log(arraysIt.next().value);
        // console.log(arraysIt.next().value);
        // console.log(arraysIt.next().value);
        // console.log(arraysIt.next().value);
        // console.log(arraysIt.next().value);  

        for(var v of arrays){
            console.log(v);
        }

    </script>
</head>
<body>
    
</body>
</html>